/*
5 4 2
1 2
2 3
5 2
1 3*/

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define MAX_N 1000

int graph[MAX_N + 1][MAX_N + 1] = {0}; // 邻接矩阵，存储图的信息
bool visited[MAX_N + 1] = {false};     // 记录每个顶点是否被访问过
int N, M, S;                           // 顶点数、边数和起点

void dfs(int v)
{
    printf("%d ", v);
    visited[v] = true;
    for (int i = 1; i <= N; i++)
    {
        if (graph[v][i] && !visited[i])
        {
            dfs(i);
        }
    }
}

bool is_connected()
{
    for (int i = 1; i <= N; i++)
    {
        if (!visited[i])
        {
            return false;
        }
    }
    return true;
}

int main()
{
    scanf("%d %d %d", &N, &M, &S);
    for (int i = 0; i < M; i++)
    {
        int u, v;
        scanf("%d %d", &u, &v);
        graph[u][v] = 1;
        graph[v][u] = 1; // 无向图的对称边
    }

    dfs(S);
    printf("\n");

    if (!is_connected())
    {
        printf("Non-connected\n");
    }

    return 0;
}
